<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<base href="<%=basePath%>">
		<meta charset="utf-8" />
		<title></title>
		<meta name="description" content="overview & stats" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<link rel="stylesheet" href="static/css/bootstrap.min.css" />
		<link rel="stylesheet" href="static/css/bootstrap-responsive.min.css" />
		<link rel="stylesheet" href="static/css/font-awesome.min.css" />
		<!-- 下拉框 -->
		<link rel="stylesheet" href="static/css/chosen.css" />
		<link rel="stylesheet" href="static/css/ace.min.css" />
		<link rel="stylesheet" href="static/css/ace-responsive.min.css" />
		<link rel="stylesheet" href="static/css/ace-skins.min.css" />
		<style type="text/css">
		input, textarea, .uneditable-input {
		    width: 306px;
		}
		</style>
		<script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
		<!--提示框-->
		<script type="text/javascript" src="static/js/jquery.tips.js"></script>
		<script type="text/javascript">
			$(top.hangge());
			$(document).ready(function(){
				if($("#organid").val()!=""){
					$("#organname").attr("readonly","readonly");
					$("#organname").css("color","gray");
				}
			});
			
			//保存
			function save(){
				if($("#organname").val()=="" || $("#organname").val()=="此机构名称已存在!"){
					$("#organname").tips({
						side:3,
			            msg:'输入机构名称',
			            bg:'#AE81FF',
			            time:2
			        });
					
					$("#organname").focus();
					$("#organname").val('');
					$("#organname").css("background-color","white");
					return false;
				}else{
					$("#organname").val(jQuery.trim($('#organname').val()));
				}
				
				if($("#nickname").val()==""){
					$("#nickname").tips({
						side:3,
			            msg:'输入姓名',
			            bg:'#AE81FF',
			            time:3
			        });
					$("#nickname").focus();
					return false;
				}
				
				var myreg = /^(((13[0-9]{1})|15[0-9]{1}|18[0-9]{1}|14[0-9]{1})+\d{8})$/;
				var myreg2 = /^([0-9]{3,4}-)?[0-9]{7,8}$/;
				if($("#phonenumber").val()!=""){
					if( !(myreg.test($("#phonenumber").val()) || myreg2.test($("#phonenumber").val())) ){
						$("#phonenumber").tips({
							side:3,
				            msg:'电话号码格式不正确',
				            bg:'#AE81FF',
				            time:3
				        });
						$("#phonenumber").focus();
						return false;
					}
				}
				
				if($("#email").val()!=""){
					if(!ismail($("#email").val())){
						$("#email").tips({
							side:3,
				            msg:'邮箱格式不正确',
				            bg:'#AE81FF',
				            time:3
				        });
						$("#email").focus();
						return false;
					}
				}
				
				$("#organForm").submit();
				$("#centerOfMainFrame").hide();
				$("#centerOfMainFrame2").show();
			}
			
			function ismail(mail){
				return(new RegExp(/^(?:[a-zA-Z0-9]+[_\-\+\.]?)*[a-zA-Z0-9]+@(?:([a-zA-Z0-9]+[_\-]?)*[a-zA-Z0-9]+\.)+([a-zA-Z]{2,})+$/).test(mail));
			}
			
			$(document).ready(function(){
				var provincecode = $("#hiddenProvinceCode").val();
				var citycode = $("#hiddenCityCode").val();
				var areacode = $("#hiddenAreaCode").val();
				//alert(provincecode);
				getProvince(provincecode, citycode, areacode);
			});
			
			function getProvince(provincecode, citycode, areacode) {
					$.ajax( {
						type :'post',
						url :'site/queryAllProvinceList.json',
						dataType :'json',
						success : function(result) {
							//alert(result.provinceList);
							if(provincecode != null && provincecode != '' && provincecode != '0'){
								$.each(result.provinceList, function(entryIndex, entry) {
									if(provincecode == entry.provincecode){
										var html = "<option value='" + entry.provincecode + "' selected>"
												+ entry.provincename + "</option>";
										$("#selprovince").append(html);
									}else{
										var html = "<option value='" + entry.provincecode + "'>"
										+ entry.provincename + "</option>";
										$("#selprovince").append(html);
									}
								});
							}else{
								//alert("000000000000000000000000");
								$.each(result.provinceList, function(entryIndex, entry) {
									var html = "<option value='" + entry.provincecode + "'>"
											+ entry.provincename + "</option>";
									$("#selprovince").append(html);
								});
							}
						}
					});
					
					if(provincecode != null && provincecode != '' && provincecode != '0'){
						getCity(provincecode, citycode, areacode);
					}
				}

				function getCity(provincecode, citycode, areacode) {
					/* if (document.getElementById("citydiv").style.display == "block"
							|| document.getElementById("areadiv").style.display == "block") {
						document.getElementById("citydiv").style.display = "none";
						document.getElementById("areadiv").style.display = "none";
					}
					if (document.getElementById("citydiv").style.display == "none"
							&& document.getElementById("selprovince").value != 0) {
						document.getElementById("citydiv").style.display = "block";
					} */
					
					if(provincecode != null && provincecode != '' && provincecode != '0'){
						var object = provincecode;
						$.ajax( {
							type :'post',
							url :'site/queryAllCityListByProvinceCode/'+object+'.json',
							dataType :'json',
							success : function(result) {
								if(citycode != null && citycode != '' && citycode != '0'){
									$.each(result.cityList, function(entryIndex, entry) {
										if(citycode == entry["citycode"]){
											var html = "<option value='" + entry["citycode"] + "' selected>"
													+ entry["cityname"] + "</option>";
											$("#selcity").append(html);
										}else{
											var html = "<option value='" + entry["citycode"] + "'>"
											+ entry["cityname"] + "</option>";
											$("#selcity").append(html);
										}
									});
								}else{
									$.each(result.cityList, function(entryIndex, entry) {
										var html = "<option value='" + entry["citycode"] + "'>"
												+ entry["cityname"] + "</option>";
										$("#selcity").append(html);
									});
								}
							}
						});
						
						if(citycode != null && citycode != '' && citycode != '0'){
							getArea(citycode, areacode);
						}
					}else{
						$("#selcity option[value!=0]").remove();
						$("#selarea option[value!=0]").remove();
						var object = $("#selprovince");
						if (object.val() != 0) {
							$.ajax( {
								type :'post',
								url :'site/queryAllCityListByProvinceCode/'+object.val()+'.json',
								dataType :'json',
								success : function(result) {
									$.each(result.cityList, function(entryIndex, entry) {
										var html = "<option value='" + entry["citycode"] + "'>"
												+ entry["cityname"] + "</option>";
										$("#selcity").append(html);
									});
								}
							});
						}
					}
				}

				function getArea(citycode, areacode) {
					/* if (document.getElementById("areadiv").style.display == "block") {
						document.getElementById("areadiv").style.display = "none";
					}
					if (document.getElementById("areadiv").style.display == "none"
							&& document.getElementById("selcity").value != 0) {
						document.getElementById("areadiv").style.display = "block";
					} */
					
					if(citycode != null && citycode != '' && citycode != '0'){
						var object = citycode;
						$.ajax( {
							type :'post',
							url :'site/queryAllAreaListByCityCode/'+object+'.json',
							dataType :'json',
							success : function(result) {
								if(areacode != null && areacode != '' && areacode != '0'){
									$.each(result.areaList, function(entryIndex, entry) {
										if(areacode == entry["areacode"]){
											var html = "<option value='" + entry["areacode"] + "' selected>"
													+ entry["areaname"] + "</option>";
											$("#selarea").append(html);
										}else{
											var html = "<option value='" + entry["areacode"] + "'>"
											+ entry["areaname"] + "</option>";
											$("#selarea").append(html);
										}
									});
								}else{
									$.each(result.areaList, function(entryIndex, entry) {
										var html = "<option value='" + entry["areacode"] + "'>"
												+ entry["areaname"] + "</option>";
										$("#selarea").append(html);
									});
								}
							}
						});
					}else{
						$("#selarea option[value!=0]").remove();
						var object = $("#selcity");
						if (object.val() != 0) {
							$.ajax( {
								type :'post',
								url :'site/queryAllAreaListByCityCode/'+object.val()+'.json',
								dataType :'json',
								success : function(result) {
									$.each(result.areaList, function(entryIndex, entry) {
										var html = "<option value='" + entry["areacode"] + "'>"
												+ entry["areaname"] + "</option>";
										$("#selarea").append(html);
									});
								}
							});
						}
					}
				}
				
				//删除图片
				function delP(tpurl,id,target){
					 if(confirm("确定要删除图片？")){
						$.ajax({
							type : "POST",
							url : "organ/deltp/" + tpurl + "/" + target + "/" +id+ ".json",
							//data:JSON.stringify(catacode),
							contentType:"application/json",  //发送至服务器的类型
							dataType : "json",     //预期服务器返回类型
							success: function(data){
								//alert(data.string);
								//return false;
								if(data.string=="success"){
									alert("删除成功!");
									document.location.reload();
								}
							}
						})
					} 
				}
		</script>
	</head>
<body>
	<form action="<%=basePath%>/organ/editOrgan.do" name="organForm" id="organForm" method="post" enctype="multipart/form-data">
		<input type="hidden" name="currentselectorganid" id="currentselectorganid" value="${pageData.currentselectorganid }"/>
		<input type="hidden" name="organid" id="organid" value="${pageData.organid }"/>
		<input type="hidden" name="hiddenProvinceCode" id="hiddenProvinceCode" value="${pageData.provincecode }"/>
		<input type="hidden" name="hiddenCityCode" id="hiddenCityCode" value="${pageData.citycode }"/>
		<input type="hidden" name="hiddenAreaCode" id="hiddenAreaCode" value="${pageData.areacode }"/>
		<div id="centerOfMainFrame">
			<table>
				<tr>
					<td>上级机构：<input type="text" name="parentorganname" id="parentorganname" maxlength="32" value="${pageData.parentorganname }" title="上级机构名称"/></td>
				</tr>
				<tr>
					<td>机构名称：<input type="text" name="organname" id="organname" maxlength="32" placeholder="这里输入机构名称" value="${pageData.organname }" title="机构名称"/></td>
				</tr>
				<tr>
					<td>机构简称：<input type="text" name="abbrname" id="abbrname"  maxlength="32" placeholder="这里输入机构简称" value="${pageData.abbrname }" title="机构简称"/></td>
				</tr>
				<tr>
					<td>机构类型：
						<%-- <select name="organTypeId" title="机构类型">
							<option value="1" <c:if test="${pageData.organTypeId == '1' }">selected</c:if> >清吧</option>
							<option value="2" <c:if test="${pageData.organTypeId == '2' }">selected</c:if> >闹吧</option>
							<option value="3" <c:if test="${pageData.organTypeId == '3' }">selected</c:if> >慢摇吧</option>
						</select> --%>
						<form:select path="dictionary.dicvalue" items="${dictionaryList}" itemLabel="diccode" itemValue="dicvalue" title="机构类型" style="width:100px; font-size:12px;"/>
					</td>
				</tr>
				<tr>
					<td>
						<div>
						机构地址：
							<select id="selprovince" name="provincecode" style="width:100px; font-size:12px;" onchange="getCity('','','')">
								<option value="0">-请选择省份-</option>
							</select>
							<select id="selcity" name="citycode" style="width:100px; font-size:12px;" onchange="getArea('','')">
								<option value="0">-请选择城市-</option>
							</select>
							<select id="selarea" name="areacode" style="width:100px; font-size:12px;">
								<option value="0">-请选择地区-</option>
							</select>
							<!-- <span style="display: block;">
								<select id="selprovince" style="width:100px; font-size:12px;" onchange="getCity()">
									<option value="0">-请选择省份-</option>
								</select>
							</span>
							<span id="citydiv" style="display: none;">
								<select id="selcity" style="width:100px; font-size:12px;" onchange="getArea()">
									<option value="0">-请选择城市-</option>
								</select>
							</span>
							<span id="areadiv" style="display: none;">
								<select id="selarea" style="width:100px; font-size:12px;">
									<option value="0">-请选择地区-</option>
								</select>
							</span> -->
						</div>
					</td>
				</tr>
				<tr>
					<td><input type="text" name="address" id="address"  maxlength="32" placeholder="这里输入机构地址" value="${pageData.address }" title="机构地址" style="margin-left: 68px;"/></td>
				</tr>
				<tr>
					<td>商户Logo：
						<c:if test="${pageData == null || pageData.organlogo == '' || pageData.organlogo == null }">
							<input type="file" id="organlogo" name="organlogo"/>
						</c:if>
						<c:if test="${pageData != null && pageData.organlogo != '' && pageData.organlogo != null }">
							<a href="<%=basePath%>${pageData.organlogo}" target="_blank"><img src="<%=basePath%>${pageData.organlogo}" width="50"/></a>
							<input type="button" class="btn btn-mini btn-danger" value="删除" onclick="delP('${pageData.organlogo}','${pageData.organid }', '1');" />
							<input type="hidden" name="organlogohidden" id="organlogohidden" value="${pageData.organlogo }"/>
						</c:if>
					</td>
				</tr>	
				<tr>
					<td>商户平面图：
						<c:if test="${pageData == null || pageData.organplane == '' || pageData.organplane == null }">
							<input type="file" id="organplane" name="organplane"/>
						</c:if>
						<c:if test="${pageData != null && pageData.organplane != '' && pageData.organplane != null }">
							<a href="<%=basePath%>${pageData.organplane}" target="_blank"><img src="<%=basePath%>${pageData.organplane}" width="50"/></a>
							<input type="button" class="btn btn-mini btn-danger" value="删除" onclick="delP('${pageData.organplane}','${pageData.organid }', '2');" />
							<input type="hidden" name="organplanehidden" id="organplanehidden" value="${pageData.organplane }"/>
						</c:if>
					</td>
				</tr>
				<tr>
					<td>商户背景图：
						<c:if test="${pageData == null || pageData.organfrontcover == '' || pageData.organfrontcover == null }">
							<input type="file" id="organfrontcover" name="organfrontcover"/>
						</c:if>
						<c:if test="${pageData != null && pageData.organfrontcover != '' && pageData.organfrontcover != null }">
							<a href="<%=basePath%>${pageData.organfrontcover}" target="_blank"><img src="<%=basePath%>${pageData.organfrontcover}" width="50"/></a>
							<input type="button" class="btn btn-mini btn-danger" value="删除" onclick="delP('${pageData.organfrontcover}','${pageData.organid }', '3');" />
							<input type="hidden" name="organfrontcoverhidden" id="organfrontcoverhidden" value="${pageData.organfrontcover }"/>
						</c:if>
					</td>
				</tr>	
				<tr>
					<td>邮箱地址：<input type="email" name="email" id="email"  maxlength="32" placeholder="这里输入邮箱" title="邮箱" value="${pageData.email }" /></td>
				</tr>			
				<tr>
					<td>联系电话：<input type="text" name="phonenumber" id="phonenumber"  maxlength="32" placeholder="这里输入联系电话" value="${pageData.phonenumber }" title="联系电话"/></td>
				</tr>
				<tr>
					<td>机构状态：
						<select name="status" title="状态">
						<option value="1" <c:if test="${pageData.status == '1' }">selected</c:if> >正常</option>
						<option value="0" <c:if test="${pageData.status == '0' }">selected</c:if> >冻结</option>
						</select>
					</td>
				</tr>
				<tr>
					<td>机构描述：<textarea name="introduction" id="introduction" cols="100" rows="10" placeholder="这里输入机构描述">${pageData.introduction } </textarea></td>
				</tr>
				<tr>
					<td style="text-align: center;">
						<a class="btn btn-mini btn-primary" onclick="save();">保存</a>
						<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
					</td>
				</tr>
			</table>
		</div>
		<input type="hidden" name="token" value="${token}" />
		<div id="centerOfMainFrame2" class="center" style="display:none"><br/><br/><br/><br/><img src="static/images/jiazai.gif" /><br/><h4 class="lighter block green"></h4></div>
	</form>
	
		<!-- 引入 -->
		<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
		<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
		<script type="text/javascript" src="static/js/ace-elements.min.js"></script>
		<script type="text/javascript" src="static/js/ace.min.js"></script>
		<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
		<script type="text/javascript">
		//上传
		$('#organlogo').ace_file_input({
			no_file:'请选择图片 ...',
			btn_choose:'选择',
			btn_change:'更改',
			droppable:false,
			onchange:null,
			thumbnail:false //| true | large
			//whitelist:'gif|png|jpg|jpeg'
			//blacklist:'exe|php'
			//onchange:''
			//
		});
		
		//上传
		$('#organplane').ace_file_input({
			no_file:'请选择图片 ...',
			btn_choose:'选择',
			btn_change:'更改',
			droppable:false,
			onchange:null,
			thumbnail:false //| true | large
			//whitelist:'gif|png|jpg|jpeg'
			//blacklist:'exe|php'
			//onchange:''
			//
		});
		
		//上传
		$('#organfrontcover').ace_file_input({
			no_file:'请选择图片 ...',
			btn_choose:'选择',
			btn_change:'更改',
			droppable:false,
			onchange:null,
			thumbnail:false //| true | large
			//whitelist:'gif|png|jpg|jpeg'
			//blacklist:'exe|php'
			//onchange:''
			//
		});
		</script>
</body>
</html>